package com.example.carrierapp.viewmodel.viewmodel

import android.view.View
import com.example.carrierapp.util.AppUtil
import com.google.gson.annotations.SerializedName

class DispatchDeliverModel {

    var id = 0
    // 过期时间
    var expires: String? = ""
        get() = if (field.isNullOrEmpty()) "" else field?.split("T")?.get(0)

    var shipmentNumber = ""// 发货编码

    var isSingle = false //  是否单次

    @SerializedName("isShort")
    var showShort = false //  是否短倒

    var productId = 0 //   产品Id

    var proName = ""// 货物名称

    var shipperId = 0 //   托运人ID

    var shipperName = ""// 托运人名称

    var settlementType = 0 //   结算方式= ['1' '2' '3']

    var settlementTypeName = "" //   发货计划结算方式名称

    var estimatedVolumes = 0f //   预计运量

    var distance = 0f //   公里数

    var lodingNumber = 0 //   装货编号

    var lodingName = ""// 装货地市区

    var lodingDetail = ""// 装货详细地址

    var unloadNumber = 0 //   卸货编号

    var unloadName = ""// 卸货地市区

    var unloadDetail = ""// 卸货详细地址

    var winPrice = 0f //   中标价格

    var lodingPersonName = ""// 发货人名称

    // 发货人手机
    var lodingPersonPhone = ""
        get() = if (field.isNullOrEmpty()) "暂无电话" else field

    // 发货人期望时间
    var lodingExpectTime: String? = ""
        get() = if (field.isNullOrEmpty()) "" else field?.split("T")?.get(0)

    var unloadPersonName = ""// 收货人名称

    // 收货人手机
    var unloadPersonPhone = ""
        get() = if (field.isNullOrEmpty()) "暂无电话" else field

    // 收货人期望时间
    var unloadExpectTime: String? = ""
        get() = if (field.isNullOrEmpty()) "" else field?.split("T")?.get(0)

    // 备注
    var remarks = ""
        get() = if (field.isNullOrEmpty()) "无" else field

    var carTypeStr = ""// 车辆类型

    var carLengthStr = ""// 车辆长度

    var buszName = ""// 业务人员名称
    // 业务人员电话
    var buszPhone = ""
        get() = if (field.isNullOrEmpty()) "暂无电话" else field

    var proPicPath = ""// 货物图片路径

    private var dispatchedCarNumber = 0 //   已调度车辆数

    private var dispatchedFreightVolume = 0f //   已调度运量

    private var completedCarNumber = 0 //   已送达车辆数

    private var completedFreightVolume = 0f //   已送达运量

    var displayText = ""
        get() = "$proName | " + when (settlementType) {
            3 -> "${estimatedVolumes}吨/${distance}公里"
            else -> "${estimatedVolumes}吨"
        }

    var dispatchedText = ""
        get() = " ${dispatchedCarNumber}车 | ${dispatchedFreightVolume}吨"

    var completedText = ""
        get() = " ${completedCarNumber}车 | ${completedFreightVolume}吨"

    fun callPhone(view: View) {
        AppUtil.callNumber(view.context, when (view.tag) {
            "0" -> buszPhone
            "1" -> lodingPersonPhone
            else -> unloadPersonPhone
        })
    }

}